#!/usr/bin/env python
# encoding: utf-8
"""
sax.py

Starting point for implementing a handler for
XML documents on top of the sax-parser interface.

"""


import sys
from xml.sax import make_parser
from xml.sax.handler import ContentHandler
from xml.sax.handler import EntityResolver
from xml.sax.handler import ErrorHandler


class Handler(ContentHandler):
    ''' Handler for XML Docs '''

    def startElement(self, name, attrs):
        print "Start: ", name

    def endElement(self, name):
        pass

    def characters(self, characters):
        pass



class Resolver(EntityResolver):
    
    def resolveEntity(self, publicID, systemID):
        if systemID:
            print systemID

class Error(ErrorHandler):

    def error(self, exception):
        pass

    def fatalError(self, exception):
        print exception




if __name__ == "__main__":

    h=Handler()
    r=Resolver()
    e=Error()
    
    saxparser=make_parser()

    saxparser.setContentHandler(h)
    saxparser.setEntityResolver(r)
    saxparser.setErrorHandler(e)
    
    saxparser.parse('myCorpus.xml')
